/* ==================================================================   
 * Created [2009-4-27 下午11:32:55] by Jon.King 
 * ==================================================================  
 * TSS 
 * ================================================================== 
 * mailTo:jinpujun@hotmail.com
 * Copyright (c) Jon.King, 2009-2012 
 * ================================================================== 
 */

package com.jinhe.tss.cms.helper.parser;

import java.util.List;

import com.jinhe.tss.cms.entity.ArticleScore;
import com.jinhe.tss.core.util.EasyUtils;
import com.jinhe.tss.core.web.dispaly.grid.GridNode;
import com.jinhe.tss.core.web.dispaly.grid.GridParser;

public class ScoreGridParser extends GridParser {

	public GridNode parse(Object data, int dataType) {
		List<?> list = (List<?>) data;
		
		if( EasyUtils.isNullOrEmpty(list) ) return null;
		
		GridNode root = new GridNode();
		for (int i = 0; i < list.size(); i++) {
			Object[] obj = (Object[]) list.get(i);
			
			ArticleScore scorer = new ArticleScore();
			scorer.setAuthor((String) obj[0]);
			scorer.setAverageScore( obj[1] == null ? "0" : String.valueOf(obj[1]) );
			scorer.setHitCount(String.valueOf(obj[2]));
			scorer.setArticleCount(String.valueOf(obj[3]));
			scorer.setScoreCount( obj[4] == null ? "0" : String.valueOf(obj[4]) );
			
			root.addChild(new GridNode(scorer, this.getColumns(),dataType));
		}
		return root;
	}
}
